﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using NLog;
using NLog.Config;
using NLog.Targets;
using SsoaFramework.Service;

namespace TestService
{
    class Program
    {
        public static Guid guid = Guid.NewGuid();
        static Random rand = new Random();
        public static LogService logService;
        static void Main(string[] args)
        {
            logService = new LogService("Echo");

            using (StandardizedServiceHost host = new StandardizedServiceHost(typeof(Echo),new Uri("http://localhost:3"+rand.Next(100,999))))
            {
                host.AddServiceEndpoint(typeof (IEcho), new WSHttpBinding(), String.Empty);
                //logService.Info("EchoService started", guid);
                host.Open();
                string message;
                while (( message = Console.ReadLine()) != String.Empty)
                {
                    logService.Info(message, guid);
                }
                logService.Info("EchoService stopping", guid);
            }
        }
    }

    public class Echo : IEcho
    {
        public string SendMessage(string message)
        {
            System.Diagnostics.Trace.WriteLine(message);
            Program.logService.Info("EchoService invoked! Message: "+message, Program.guid);
            return message + "Suffix";
        }
    }

    [ServiceContract]
    internal interface IEcho
    {
        [OperationContract]
        string SendMessage(string message);
    }
}
